#include <iostream>
#include <stdlib.h>
#include <time.h>
typedef struct Node{
    int value;
    struct Node *next;
}Node;


int main(){
    double dur;
	clock_t start,end;
    int num,target;
    std::cin>>num>>target;
	start=clock();
    
    Node *head=NULL;
    head = (Node*)malloc(sizeof(Node));
    Node *current=head;
    Node *after=NULL;
    current->value=0;
    for (int i=1;i<num;i++){
        after=(Node*)malloc(sizeof(Node));
        after->value=i;
        current->next=after;
        current=current->next;
    }
    current->next=head;
    while (current->next!=current){
        for (int j=0;j<target-1;j++)
            current=current->next;
        after=current->next;
        current->next=after->next;
        free(after);
    }
    std::cout<<current->value<<std::endl;
    end=clock();
	dur=(double) end-start;
	std::cout<<dur<<std::endl;
    return 0;
}